// 1.下载路由 npm i vue-router@3
// 2.引入Vue
import Vue from 'vue';
// 3.引用vue-router
import VueRouter from 'vue-router';
Vue.use(VueRouter)
// 4.创建路由规则
// 4.1引入页面级组件---初始化就已经加载完毕
import Home from '@/views/home/home'
import Category from '@/views/category/category'
import Find from '@/views/find/find'
import Cart from '@/views/cart/cart'
import Mine from '@/views/mine/mine'
// 4.2配置路由
var routes = [{
        path: '/',
        redirect: '/home'
    },
    {
        path: '/home',
        component: Home,
        // 路由元信息
        meta: {
            showTabbar: true
        }
    },
    {
        path: '/category',
        component: Category,
        // 路由元信息
        meta: {
            showTabbar: true
        }
    },
    {
        path: '/find',
        component: Find,
        // 路由元信息
        meta: {
            showTabbar: true
        }
    },
    {
        path: '/cart',
        component: Cart,
        // 路由元信息
        meta: {
            showTabbar: true
        },
        beforeEnter: (to, from, next) => {
            if (localStorage.getItem('login')) {
                next()
            } else {
                alert('您还未登录');
                router.push('/login')
            }
        }
    }, {
        path: '/mine',
        component: Mine,
        // 路由元信息
        meta: {
            showTabbar: true
        },
        beforeEnter: (to, from, next) => {
            if (localStorage.getItem('login')) {
                next()
            } else {
                alert('您还未登录');
                router.push('/login')
            }
        }
    }, {
        path: '/login',
        component: () => import('@/views/login/login'),
        meta: {
            showTabbar: false
        }
    }, {
        path: '/search',
        component: () => import('@/views/search/search'),
        meta: {
            showTabbar: true
        },
        name: 'search'
    },
    {
        path: '/list/:id',
        name: 'list',
        component: () => import('@/views/list')
    },
    {
        path: '/goods/:id',
        name: 'goods',
        component: () => import('@/views/detail')
    },
    {
        path:'/register',
        name:'register',
        component:()=>import('@/views/register')
    }
]
// 5.实例化一个路由对象
var router = new VueRouter({
    routes
})
// router.beforeEach((to, from, next) => {

// })
// 6.暴漏--实例化对象
export default router